#ifndef HMS_LOGGER_HPP
#define HMS_LOGGER_HPP

#include "formatHelpers.hpp"
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/async.h>

#include <fmt.h>

#include <limits>
#include <filesystem>

namespace hms::log {

using spdlog::logger;
using spdlog::critical;
using spdlog::error;
using spdlog::warn;
using spdlog::info;
using spdlog::debug;
using spdlog::trace;
using Level = spdlog::level::level_enum;

namespace fs = std::filesystem;

enum class Sink {
	console,
	file,
	nSinks
};

struct Settings {
	/* appropriate default log levels for Debug and Release mode */
	#ifndef NDEBUG
	Level logLevel_console { Level::debug };
	Level logLevel_file { Level::trace };
	#else
	Level logLevel_console { Level::warn };
	Level logLevel_file { Level::info };
	#endif

	bool useLogFile {false};
	fs::path logDirectory;
	std::string logFileName { "hms_log.txt" };

	bool appendLog {false};

	bool useLogFileRotation {true};
	int logRotationMaxFiles { std::numeric_limits<int>::max() };
	long logRotationMaxSizeKB {4096};

	bool useCustomLogFormat_file {false};
	std::string customLogFormat_file {"[%T] [%l] %v" };

	bool useCustomLogFormat_console {false};
	std::string customLogFormat_console {"[%^%l%$] %v" };

	bool useAsyncLogger {false};
};

constexpr auto loggerName { "hmsLogger" };

std::shared_ptr<logger> createLogger( const Settings& );

std::shared_ptr<logger> getLogger();

void setLevel( std::shared_ptr<logger>&, Sink, Level );

void setLevel(Sink, Level);

} // namespace hms::logger


#endif